# coding=utf-8
import time
from typing import List, Optional
from smartpi import base_driver

# 颜色传感器读取
# port: 连接P端口 (0-7)
# 正常返回：颜色值 (1-红色, 2-绿色, 3-蓝色, 4-黄色, 5-紫色, 6-青色)
# 读取错误：返回None
def get_value(port:bytes) -> Optional[bytes]:
    color_str=[0xA0, 0x04, 0x00, 0xBE]
    color_str[0]=0XA0+port
    color_str[2]=1
    response = base_driver.single_operate_sensor(color_str,0)        
    if response == None:
        return None
    else:
        return response[4]